﻿using System;
using System.Security.Principal;
using System.Web.Security;
using Application.MainModule.UserManagement;

namespace Presentation.Web.UI.ViewModels
{
    public class WebIdentity : IIdentity
    {
        public WebIdentity(FormsAuthenticationTicket ticket)
            : this(ticket.Name, UserDTO.FromString(ticket.UserData))
        {
            if (ticket == null) throw new ArgumentNullException("ticket");
        }

        public WebIdentity(string name, UserDTO user)
            : this(name, user.CustomerName, user.CustomerId)
        {
            if (user == null) throw new ArgumentNullException("user Info");
            this.CustomerId = user.CustomerId;
        }

        public WebIdentity(string name, string displayName, int customerId)
        {
            this.Name = name;
            this.CustomerName = displayName;
            this.CustomerId = customerId;
        }

        public string AuthenticationType
        {
            get { return "Presentation.Web.UI"; }
        }

        public bool IsAuthenticated
        {
            get { return !String.IsNullOrEmpty(Name); }
        }
        public string CustomerName { get; private set; }
        public string Name { get; private set; }
        public int CustomerId { get; private set; }
    }
}
